ServerFeed [C#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication1.ServiceReference1;
using System.Collections.ObjectModel;
namespace WpfApplication1
{
public partial class ServerFeed : UserControl
{
ServiceSample sample = new ServiceSample();
public ServerFeed()
{
InitializeComponent();
}
public ServerFeed(string login, string password)
{
InitializeComponent();
List<View_Group> listResult;
sample.GetGroup(out listResult, login, password);
treeGroup.ItemsSource = TreeNode.GetTreeNode(listResult);
}
private void treeGroup_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
List<XMLMedia> listResult;
sample.GetXMLMedia(out listResult, (treeGroup.SelectedItem as TreeNode).Id??0);
comboFeed.ItemsSource = (from l1 in listResult where l1.TypeId == 1 select l1).ToList();
}
private void comboFeed_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboFeed.SelectedItem == null)
{
gridFeedData.ItemsSource = null;
return;
}
ObservableCollection<FeedRow> listRow = new ObservableCollection<FeedRow>();
for (int i = 0; i < 30; i++)
{
listRow.Add(new FeedRow((comboFeed.SelectedItem as XMLMedia).Id, i));
}
List<XMLMediaData> listResult;
sample.GetXMLMediaData(out listResult, (comboFeed.SelectedItem as XMLMedia).Id);
for (int i = 0; i < listResult.Count; i++)
{
listRow[listResult[i].RowIndex ?? 0].ListColData.Add(listResult[i]);
}
gridFeedData.ItemsSource = listRow;
}
private void btnValidate_Click(object sender, RoutedEventArgs e)
{
List<XMLMediaData> listResult = new List<XMLMediaData>();
(from l1 in (gridFeedData.ItemsSource as ObservableCollection<FeedRow>) select l1.ListColUpdated).ToList().ForEach(x => listResult.AddRange(x)); ;
sample.SetXMLMediaData(listResult);
}
private void gridFeedData_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
}
}
public class FeedRow
{
public long XMLMediaId;
public int RowIndex;
public List<XMLMediaData> ListColData = new List<XMLMediaData>();
public FeedRow(long xmlMediaId, int rowIndex)
{
this.XMLMediaId = xmlMediaId;
this.RowIndex = rowIndex;
}
public List<XMLMediaData> ListColUpdated
{
get
{
return (from l1 in ListColData where ListUpdatedIndex.Contains(l1.ColumnIndex ?? -1) select l1).Distinct().ToList();
}
}
public string ColA
{
get { return GetColByIndex(0); }
set { SetColByIndex(0, value); }
}
public string ColB
{
get { return GetColByIndex(1); }
set { SetColByIndex(1, value); }
}
public string ColC
{
get { return GetColByIndex(2); }
set { SetColByIndex(2, value); }
}
public string ColD
{
get { return GetColByIndex(3); }
set { SetColByIndex(3, value); }
}
public string ColE
{
get { return GetColByIndex(4); }
set { SetColByIndex(4, value); }
}
string GetColByIndex(int index)
{
var item = (from l1 in ListColData where l1.ColumnIndex == index select l1).FirstOrDefault();
return item == null ? "" : item.Text;
}
void SetColByIndex(int index, string value)
{
var item = (from l1 in ListColData where l1.ColumnIndex == index select l1).FirstOrDefault();
if (item == null)
{
item = new XMLMediaData() { ColumnIndex = index, Text = value, XMLMediaId = XMLMediaId, RowIndex = RowIndex };
}
else
{
item.Text = value;
}
ListColData.Add(item);
if (!ListUpdatedIndex.Contains(index)) ListUpdatedIndex.Add(index);
}
List<int> ListUpdatedIndex = new List<int>();
}
}